//
//  SGY_NormalNaviView.m
//  differentThoughts
//
//  Created by 如沐春风 on 2021/5/10.
//

#import "SGY_NormalNaviView.h"

@interface SGY_NormalNaviView ()
{
    UILabel *titleLabel;
    UIButton *rightBtn;
}
/**
 *
 **/
@property(nonatomic, copy)void (^rightActionBlock)(void);
@end
@implementation SGY_NormalNaviView


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        UIView *bgView = [ViewCreate createLineFrame:CGRectMake(0, 0, SCREEN_WIDTH, kTopHeight) backgroundColor:kThemeColor];
        [self addSubview:bgView];
        
//        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:bgView.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(10, 10)];
//        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
//        maskLayer.frame = bgView.bounds;
//        maskLayer.path = maskPath.CGPath;
//        bgView.layer.mask = maskLayer;
        
        
        titleLabel = [ViewCreate createLabelFrame:CGRectZero backgroundColor:ClearColor text:@"" textColor:kWhiteColor textAlignment:Center font:FONT(18)];
        [self addSubview:titleLabel];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_offset(0);
            make.bottom.mas_offset(-SIZE(13));
            make.height.mas_offset(SIZE(20));
        }];
        
        UIButton *leftBtn = [ViewCreate createButtonFrame:CGRectZero normalImage:@"nav_back_icon" selectedImage:@"nav_back_icon"];
        [self addSubview:leftBtn];
        [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
        [leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(titleLabel.mas_centerY).mas_offset(0);
            make.left.mas_offset(SIZE(5));
            make.width.height.mas_offset(SIZE(44));
        }];
        
        rightBtn = [ViewCreate createButtonFrame:CGRectZero normalImage:@"wenhao" selectedImage:@"wenhao"];
        [self addSubview:rightBtn];
        rightBtn.hidden = YES;
        [rightBtn addTarget:self action:@selector(rightAction) forControlEvents:UIControlEventTouchUpInside];
        [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(titleLabel.mas_centerY).mas_offset(0);
            make.right.mas_offset(-SIZE(20));
            make.width.height.mas_offset(SIZE(25));
        }];
    }
    return self;
}
- (void )backAction{
    if (self.backActionBlock) {
        self.backActionBlock();
    }
}


- (void )rightAction{
    if (self.rightActionBlock) {
        self.rightActionBlock();
    }
}
-(void)configRightIconWithName:(NSString *)iconName rightAction:(void (^)(void))rightAction{
    if (isEmptyStr(iconName)) {
        return;
    }
    rightBtn.hidden = NO;
    [rightBtn setImage:GetImage(iconName) forState:UIControlStateNormal];
    self.rightActionBlock = rightAction;
}
-(void)setNaviTitle:(NSString *)naviTitle{
    _naviTitle = naviTitle;
    titleLabel.text = _naviTitle;
}
@end
